//包含n个reducer函数,根据老的state和action返回一个新的state4
import { combineReducers } from "redux"
import { ADDUSERNAME, ADDCONTEXT, CLEARALL, SUBMITLIST, DELITEM } from "./action-types"
const initComments = [{ username: "ojj", context: "react-test" }]
function comments(state = initComments, action) {
    console.log("===========comment:", state, action);
    switch (action.type) {
        case SUBMITLIST:
            return [action.data, ...state]
        case DELITEM:
            return state.filter((item, index) => index !== action.data.index)
        case CLEARALL:
            return []
        default:
            return state
    }
}

function username(state = "ojj", action) {
    switch (action.type) {
        case ADDUSERNAME:
            return action.data
        default:
            return state
    }
}

function context(state = "无内容", action) {
    switch (action.type) {
        case ADDCONTEXT:
            return action.data
        default:
            return state
    }
}

export default combineReducers({
    commentList: comments,
    username,
    context
})